home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / menu / string.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-14  |  1.3 KB  |  65 lines

  1. /* -*- c -*- ------------------------------------------------------------- *
  2.  *
  3.  *   Copyright 2004 Murali Krishnan Ganapathy - All Rights Reserved
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8.  *   Boston MA 02111-1307, USA; either version 2 of the License, or
  9.  *   (at your option) any later version; incorporated herein by reference.
  10.  *
  11.  * ----------------------------------------------------------------------- */
  12.  
  13. #include "string.h"
  14.  
  15. /* String routines */
  16. void *memset(void *buf, int chr, unsigned int len)
  17. {
  18.   asm("cld ; rep ; stosb" : "+D" (buf), "+c" (len) : "a" (chr));
  19.   return buf;
  20. }
  21.  
  22. char *strcpy(char *dst, const char *src)
  23. {
  24.   char *r = dst;
  25.   char c;
  26.  
  27.   do { 
  28.     c = *src++;
  29.     *dst++ = c;
  30.   } while ( c );
  31.  
  32.   return r;
  33. }
  34.  
  35. char *strcat(char *dst, const char * src)
  36. {
  37.   char *r = dst;
  38.  
  39.   while (*dst++); // Find end of string
  40.   dst--;
  41.   while (*src) *dst++ = *src++; // Append
  42.   *dst = '\0'; // Terminate string
  43.  
  44.   return r;
  45. }
  46.  
  47. int strcmp(const char *a, const char*b)
  48. {
  49.     while (*a)
  50.     {
  51.         if (*a < *b) return -1;
  52.         if (*a++ > *b++) return 1;
  53.     }
  54.     if (*b) return 1; else return 0;
  55. }
  56.  
  57. int strlen(const char *a)
  58. {
  59.   int ans = 0;
  60.   
  61.   while (*a++) ans++;
  62.   return ans;
  63. }
  64.  
  65.